#ifndef CLIENTVIEW_H
#define CLIENTVIEW_H

#include <QWidget>
#include <QScreen>

// view中的各种对象后面要全部放到model中
#include <QDebug>
#include <QMessageBox>
#include <QTcpSocket>
#include <QUdpSocket>
#include <QTextDocument>
#include <QTextBlock>
#include <QAbstractSocket>

#include "tcpstatedialog.h"
#include "../../observer/viewsubject.h"

namespace Ui {
class ClientView;
}

class ClientView : public QWidget,public ViewSubject
{
    Q_OBJECT

public:
    explicit ClientView(QWidget *parent = nullptr);
    void init();
    ~ClientView();

public slots:

    void onConnection();

    void onDisconnected();

    void onTcpConnectBtn();

    void onTCPStateChanged(QTcpSocket::SocketState sockState); // tcp连接的状态改变

    void onTCPReadyRead();

    // 清除发送、接收的文本
    void onSendClearBtnClicked();
    void onRecvClearBtnClicked();

    void onUdpConnectBtn();

    void onUDPReadyRead();

    void onUDPStateChanged(QUdpSocket::SocketState sockState);

    void onUDPCloseBtnClick();

    void onConnectFaild();



//    void onUDPErrorOccurred(QUdpSocket::SocketError error);

    void onSendBtnClicked();


private:
    Ui::ClientView *ui;
    QSharedPointer<QTcpSocket> m_tcp{nullptr};
    QSharedPointer<QUdpSocket> m_udp{nullptr};
    bool m_connected;
    QString m_UdpTargetIP;
    QString m_UdpPort;
    TCPStateDialog* m_stateDialog{new TCPStateDialog(this)};
};

#endif // CLIENTVIEW_H
